03. Create a Catkin Workspace
Create a Catkin Workspace
Step 1: Create a catkin workspace and a sub directory
All of the ROS-related code you develop throughout this course will reside in your catkin workspace. You only need to create and initialize the workspace once.
First, create the top level catkin workspace directory and a sub-directory named
src
(pronounced source). The top level directory name is arbitrary, but is often called
catkin_ws
(an abbreviation of catkin_workspace), so we will follow this convention. You can create these two directories in
/home/workspace/
with a single command:
$ mkdir -p /home/workspace/catkin_ws/src
Step 2: Navigate to the source directory
Next, navigate to the
src
directory with the cd command:
$ cd /home/workspace/catkin_ws/src
Step 3: Initialize the catkin workspace
Now you can initialize the catkin workspace which will create a
CMakeLists.txt
file:
$ catkin_init_workspace
Let’s list the contents of the current directory to see what changed.
$ ls -l
Notice that a symbolic link (
CMakeLists.txt
) has been created to
/opt/ros/kinetic/share/catkin/cmake/toplevel.cmake
Step 4: Return to top level directory
Return to the catkin_ws,
$ cd /home/workspace/catkin_ws
Step 5: Build the Workspace
$ catkin_make
Note
: you must issue this command from within the top level directory (i.e., within
catkin_ws
NOT
catkin_ws/src
)
While it is not essential that you have a deep understanding of the catkin build system, particularly if you are doing most of your development work in Python, it is helpful to learn about it. We encourage you to read the ROS wiki .
After the command is executed you will notice the output of the build processes being echoed to your display. When it has finished you should see the following lines at the end of the output:
-- BUILD_SHARED_LIBS is on
-- Configuring done
-- Generating done
-- Build files have been written to: /home/workspace/catkin_ws/build
####
#### Running command: "make -j4 -l4" in "/home/workspace/catkin_ws/build"
####
But what else has changed? Use the
ls
command again to see what is new.
$ ls
You now have two new directories:
build
and
devel
. The aptly named
build
directory is the build space for C++ packages and, for the most part, you will not interact with it. The
devel
directory does contain something of interest, a file named
setup.bash
. This setup.bash script must be sourced before using the catkin workspace with
source devel/setup.bash
Step 6: Commentary
Congratulations! You just created your first catkin workspace.
Optional
Before you begin to work with and develop your own ROS package, you can take a moment to get acquainted with catkin workspace conventional directory structure as described in the ROS Enhancement Proposal (REP) 128 by clicking here .